package com.edooteach.entity.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "user_wallet")
public class UserWallet {
	
	@Id
    @GeneratedValue
    private Long id;
	
	/**
	 * 所属用户
	 */
	@ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private User user;
	
	/**
	 * 总充值金额
	 */
	private Integer rechargeTotal;
	
	/**
	 * 充值金额余额
	 */
	private Integer rechargeRemaining;
	
	/**
	 * 消费总金额
	 */
	private Integer consumptionTotal;
	
	/**
	 * 总奖励金额
	 */
	private Integer bonusTotal;
	
	/**
	 * 奖励金余额
	 */
	private Integer bonusRemaining;
	
	private Date createTime;
	
	@Column(name = "is_disabled")
	private boolean disabled;
	
	
	public UserWallet() {
	}
	
	/**
	 * 
	 * @param user
	 */
	public UserWallet(User user) {
		this.user = user;
		this.rechargeTotal = 0;
		this.rechargeRemaining = 0;
		this.consumptionTotal = 0;
		this.bonusTotal = 0;
		this.bonusRemaining = 0;
		this.createTime = new Date();
		this.disabled = false;
	}
	
	/**
	 * 
	 * @param bonus
	 * @return
	 */
	public UserWallet addBouns(int bonus) {
		this.bonusTotal = this.bonusTotal + bonus;
		this.bonusRemaining = this.bonusRemaining + bonus;
		
		return this;
	}
	
	/**
	 * 
	 * @param recharge
	 * @return
	 */
	public UserWallet addRecharge(int recharge) {
		this.rechargeTotal = this.rechargeTotal + recharge;
		this.rechargeRemaining = this.rechargeRemaining + recharge;
		
		return this;
	}


	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}


	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}


	/**
	 * @return the rechargeTotal
	 */
	public Integer getRechargeTotal() {
		return rechargeTotal;
	}


	/**
	 * @return the rechargeRemaining
	 */
	public Integer getRechargeRemaining() {
		return rechargeRemaining;
	}


	/**
	 * @return the consumptionTotal
	 */
	public Integer getConsumptionTotal() {
		return consumptionTotal;
	}


	/**
	 * @return the bonusTotal
	 */
	public Integer getBonusTotal() {
		return bonusTotal;
	}


	/**
	 * @return the bonusRemaining
	 */
	public Integer getBonusRemaining() {
		return bonusRemaining;
	}


	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}


	/**
	 * @return the disabled
	 */
	public boolean isDisabled() {
		return disabled;
	}


	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}


	/**
	 * @param rechargeTotal the rechargeTotal to set
	 */
	public void setRechargeTotal(Integer rechargeTotal) {
		this.rechargeTotal = rechargeTotal;
	}


	/**
	 * @param rechargeRemaining the rechargeRemaining to set
	 */
	public void setRechargeRemaining(Integer rechargeRemaining) {
		this.rechargeRemaining = rechargeRemaining;
	}


	/**
	 * @param consumptionTotal the consumptionTotal to set
	 */
	public void setConsumptionTotal(Integer consumptionTotal) {
		this.consumptionTotal = consumptionTotal;
	}


	/**
	 * @param bonusTotal the bonusTotal to set
	 */
	public void setBonusTotal(Integer bonusTotal) {
		this.bonusTotal = bonusTotal;
	}


	/**
	 * @param bonusRemaining the bonusRemaining to set
	 */
	public void setBonusRemaining(Integer bonusRemaining) {
		this.bonusRemaining = bonusRemaining;
	}


	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}


	/**
	 * @param disabled the disabled to set
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
}
